<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="com.wlcorp.forcazamis.sys.util.AppConstant"%>
<%@ page import="com.wlcorp.forcazamis.domain.stock.Stock"%>
<%@ page import="com.wlcorp.forcazamis.domain.baseinfo.Factory"%>
<%@ page import="com.wlcorp.forcazamis.sys.permission.PermissionManager"%>
<%@ page import="com.wlcorp.forcazamis.sys.util.CommonUtil" %>

<%
	Stock stock = (Stock) request.getAttribute("stock");
	Factory factory = (Factory) request.getAttribute("factory");
%>
<html>
<head>
<title>采购合同编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<link href="${pageContext.request.contextPath}/css/css.css" rel=stylesheet>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/button_css.css" type="text/css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/form_css.css" type="text/css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/table_css.css" type="text/css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagetitle_css.css" type="text/css">
<script language="javascript" src="${pageContext.request.contextPath}/script/validator.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/script/calendartime.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/script/ajax.js"></script>
<script type="text/javascript">
		function doSave(){
			document.forms["stockForm"].submit();
		}
		function goback(){
			window.location = "${pageContext.request.contextPath}/stock/stockManager.do?method=stockManager";
		}
		
		function stockProduct(stockId){
			window.location = "${pageContext.request.contextPath}/stock/stockManager.do?method=getStockProductList&stockId=" + stockId;
		}
		
		function stockFitting(stockId){
			window.location = "${pageContext.request.contextPath}/stock/stockManager.do?method=getStockFittingList&stockId=" + stockId;
		}
		
		function doSubmitConfirm(){
			var sUrl = "${pageContext.request.contextPath}/confirm/confirmManager.do?method=submitConfirm"
				+ "&confirmType=<%=AppConstant.CONFIRM_TYPE_STOCK%>&itemId=${stock.stockId}";
			ajaxRead(sUrl,function(obj){
				var result = obj.responseText;
				alert(result);
				document.getElementById("submitConfirmBtn").disabled = true;
			});
		}
		
		function drawbackPI(stockId){
			var sUrl = "${pageContext.request.contextPath}/stock/stockManager.do?method=drawbackStock&stockId=" + stockId;
			ajaxRead(sUrl,function(obj){
				var result = obj.responseText;
				alert(result);
				document.getElementById("drawbackBtn").disabled = true;
			});
		}
	 
		function printStock(stockId){
			window.open("${pageContext.request.contextPath}/stock/stockManager.do?method=printStock&stockId=" + stockId);
		}
		
		function selectStockLevel(){
			var stockLevel =document.getElementsByName("stockLevel");
        	for(var i=0;i<stockLevel.length;i++){
        	 if(stockLevel[i].checked){      
        	    var at=stockLevel[i].value;
         	   if(at==0){
        	  		document.getElementById("stockLevelName").value="新单";   
         	   }
         	   if(at==1){
         	 		document.getElementById("stockLevelName").value="翻单";   
         	   }
         	   if(at==2){
         	 		document.getElementById("stockLevelName").value="新单+翻单";   
          	   }
        	 }
       	  }
		}
	</script>
</head>
<body>
<CENTER>
<form name="stockForm" method="POST" action="${pageContext.request.contextPath}/stock/stockManager.do?method=modifyStock">
<input type="hidden" name="stockId" value="${stock.stockId}" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="30">
	<tr>
		<td width="22" class="page_titlebar_head">&nbsp;</td>
		<td class="page_titlebar_bg" width="981">采购合同编辑</td>
	</tr>
</table>

<table width="900" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" class="table_bgcolor">
      <tr> 
      	<td align="left"> 
      		<input class="button_common" type="button" name="print" value="合同打印档" style="font-size:9pt" onClick="javascript:printStock('<%=stock.getStockId()%>')"> 
      	</td>
        <td align="right" valign="middle"> 
          <%
           			if (null == stock.getState()|| AppConstant.BILL_STATE_SUBMITED == stock.getState()) {
           %>
          <input class=button_save type=button name=save value="      保存" style="font-size:9pt" onClick="javascript:doSave()" id="btn_submit">
          <%
          }
          %>
          <input class=button_reset name=reset type=reset value="      恢复" style="font-size:9pt" id="btn_reset">
        <%if(null != stock.getStockId()){%>
          <input class="button_common" type=button name="submitConfirmBtn" value="提交审批" style="font-size:9pt" onClick="javascript:doSubmitConfirm()" id="submitConfirmBtn" <%if(AppConstant.BILL_STATE_PRE_CONFIRM == stock.getState() || AppConstant.BILL_STATE_CONFIRMED == stock.getState() || AppConstant.BILL_STATE_DRAWBACK == stock.getState() || null != stock.getConfirm()){out.print("disabled");}%>>
          <%}
          	if(null != stock.getState() && AppConstant.BILL_STATE_CONFIRMED == stock.getState().intValue()){
          %>
          <input class="button_common" type=button name="drawbackBtn" value="退单" style="font-size:9pt" onClick="javascript:drawbackPI('<%=stock.getStockId()%>')" id="submitConfirmBtn" >
          <%}%>
          
          <input type=button name=rst class=button_recovery value="     返回" style="font-size:9pt" onClick="javascript:history.go(-1);" id="btn_recovery">
        </td>
      </tr>
</table>
<table width="900" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="594">
	<tr>
		<td colspan="4" class="table_unfold_titlebar_small_bg">&nbsp;&nbsp;<b>合同基本信息</b></td>
	</tr>
	<tr class="InputFrameLine">
		<td class="table_label" width="17%" id="stockCode_TEXT">合同号</td>
		<td width="26%">&nbsp; <input class="input" type="text" name="stockCode" value="${stock.stockCode}" style="width: 150px" maxlength="20" disabled/></td>
		<td class="table_label" width="14%">订单等级</td>
		<td width="43%">&nbsp; 
			<select name="stockType" style="width: 150px">
				<option value="">--请选择--</option>
				<option value="T" <%if(null!=stock.getStockType()&&stock.getStockType().equals(AppConstant.STOCK_ORDER_SPECIAL)){out.print("selected");} %>>T&nbsp;•&nbsp;特级订单</option>
			 	<option value="AA" <%if(null!=stock.getStockType()&&stock.getStockType().equals(AppConstant.STOCK_ORDER_URGENCY)){out.print("selected");} %>>AA&nbsp;•&nbsp;非常紧急</option>
			 	<option value="A" <%if(null!=stock.getStockType()&&stock.getStockType().equals(AppConstant.STOCK_ORDER_GENERAL)){out.print("selected");} %>>A&nbsp;•&nbsp;一般紧急</option>
			 	<option value="B" <%if(null!=stock.getStockType()&&stock.getStockType().equals(AppConstant.STOCK_ORDER_NORMAL)){out.print("selected");} %>>B&nbsp;•&nbsp;正常生产</option>
			 	<option value="C" <%if(null!=stock.getStockType()&&stock.getStockType().equals(AppConstant.STOCK_ORDER_LONG)){out.print("selected");} %>>C&nbsp;•&nbsp;较长生产</option>
			 	<option value="D" <%if(null!=stock.getStockType()&&stock.getStockType().equals(AppConstant.STOCK_ORDER_OVER)){out.print("selected");} %>>D&nbsp;•&nbsp;超长生产</option>
			</select></td>
    </tr>
	<tr class="InputFrameLine">
		<td class="table_label" width="17%">下单日期</td>
		<td width="26%">&nbsp; <input name="stockDate" class="input" type="text" value="${stock.stockDate}" onClick="setDay(this);"/></td>
		<td class="table_label" width="14%" id="stockLevel_TEXT">订单类型</td>
		<td width="43%">&nbsp; <input class="input" type="text" name="stockLevelName" value="${stock.stockLevelName}" style="width: 150px" maxlength="20" />&nbsp;[必选]</td>
	</tr>
	<tr class="InputFrameLine">
		<td class="table_label" width="17%" id="deliveryDate_TEXT">交货日期</td>
		<td >&nbsp; <input class="input" type="text" name="deliveryDate" value="${stock.deliveryDate}" onClick="setDay(this);"/></td>
		<td class="table_label" width="13%"></td>
		<td width="28%">
			<input type="radio" name="stockLevel" onclick="selectStockLevel()" value="<%=AppConstant.STOCK_NEW%>"  <%if(stock.getStockLevel().equals(AppConstant.STOCK_NEW)){out.print("checked");}%>/>新单&nbsp;
			<input type="radio" name="stockLevel" onclick="selectStockLevel()" value="<%=AppConstant.STOCK_OLD%>"  <%if(stock.getStockLevel().equals(AppConstant.STOCK_OLD)){out.print("checked");}%>/>翻单&nbsp;
			<input type="radio" name="stockLevel" onclick="selectStockLevel()" value="<%=AppConstant.STOCK_BOTH%>"  <%if(stock.getStockLevel().equals(AppConstant.STOCK_BOTH)){out.print("checked");}%>/>新单+翻单&nbsp;
		</td>
	</tr>
	<tr class="InputFrameLine">
		<td class="table_label" width="17%" id="factoryCode_TEXT">供应商编号</td>
		<td width="26%">&nbsp; <input class="input" type="text" name="factoryCode" value="${stock.factory.factoryCode}" disabled/></td>
		<td class="table_label" width="14%" id="name_TEXT">联系人</td>
		<td width="43%">&nbsp; <select name="supplierLinkman" style="width: 150px">
			<option value="">--请选择--</option>
			<%
						if (null != stock.getFactory().getOwnerName()
						&& !stock.getFactory().getOwnerName().equals("")) {
			%>
			<option value="<%=stock.getFactory().getOwnerName() %>" <%if(null!=stock.getSupplierLinkman()&&stock.getSupplierLinkman().equals(stock.getFactory().getOwnerName())){out.print("selected");} %>><%=stock.getFactory().getOwnerName()%> - [ 老板 ]</option>
			<%
			}
			%>
			<%
						if (null != stock.getFactory().getManagerName()
						&& !stock.getFactory().getManagerName().equals("")) {
			%>
			<option value="<%=stock.getFactory().getManagerName() %>" <%if(null!=stock.getSupplierLinkman()&&stock.getSupplierLinkman().equals(stock.getFactory().getManagerName())){out.print("selected");} %>><%=stock.getFactory().getManagerName()%> - [ 负责人 ]</option>
			<%
			}
			%>
			<%
						if (null != stock.getFactory().getOtherManager()
						&& !stock.getFactory().getOtherManager().equals("")) {
			%>
			<option value="<%=stock.getFactory().getOtherManager() %>" <%if(null!=stock.getSupplierLinkman()&&stock.getSupplierLinkman().equals(stock.getFactory().getOtherManager())){out.print("selected");} %>><%=stock.getFactory().getOtherManager()%> - [ 其他负责人 ]</option>
			<%
			}
			%>

		</select></td>
	</tr>
	<tr class="InputFrameLine">
		<td class="table_label" width="17%" id="factoryName_TEXT">供应商名</td>
		<td width="26%">&nbsp; <input class="input" name="factoryName" type="text" value="${stock.factory.factoryFullName}" maxlength="100" size="50" disabled/></td>
	</tr>
	
	<tr bgcolor="#ffffff">
		<td colspan="10" align="center">
		<input type="button" name="piproductDetailButton" class="button_common_5" value="产品细节编辑" onClick="stockProduct('${stock.stockId}')"
			<%if(null == stock.getStockId()){out.print("disabled");}%> />&nbsp; 
			<!--  input type="button" name="pifittingDetailButton" class="button_common_5" value="配件细节编辑" onClick="stockFitting('${stock.stockId}')"
			<%if(null == stock.getStockId()){out.print("disabled");}%> /-->
		</td>
	</tr>

	<tr class="InputFrameLine">
		<td class="table_label" colspan="4">
		<table width="100%" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="80">
			<tr>
				<td class="table_unfold_titlebar_small_bg" colspan="4">&nbsp;&nbsp;<strong>合同信息</strong></td>
			</tr>
			<tr class="InputFrameLine">
				<td class="table_label" width="10%" id="staffName_TEXT">合同编写人:&nbsp;</td>
				<td>&nbsp;${stock.creator.staffName}</td>
				<td class="table_label" width="10%" id="transportType_TEXT">&nbsp;</td>
				<td width="40%">&nbsp;</td>
			</tr>
			<tr class="InputFrameLine">
				<td class="table_label" width="10%" id="totalPrice_TEXT">合同总金额:&nbsp;</td>
				<td><%=CommonUtil.format2Scale(stock.getTotalPrice())%></td>
				<td class="table_label" width="10%" id="totalGlasses_TEXT">镜架总付数:&nbsp;</td>
				<td width="40%">${stock.totalGlasses}</td>
			</tr>
		</table>
		</td>
	</tr>
	
	<tr class="InputFrameLine">
		<td height="346" colspan="4" class="table_label">
		<table width="100%" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="340">
			<tr>
				<td class="table_unfold_titlebar_small_bg" colspan="4">&nbsp;&nbsp;<strong>合同要求</strong></td>
			</tr>
			<tr class="InputFrameLine">
				<td class="table_label" width="10%" id="otherPromise_TEXT">其它约定&nbsp;</td>
				<td width="90%">&nbsp;<input class="input" name="otherPromise" type="text" value="${stock.otherPromise}" size="200" style="width: 300px" maxlength="500" /></td>
			</tr>
			<tr class="InputFrameLine">
				<td width="10%" height="90" class="table_label" id="qualityRequire_TEXT">质量要求</td>
			  <td colspan="3"> &nbsp;<textarea name="qualityRequire" cols="60" rows="5" style="width: 90%" wrap="hard">${stock.qualityRequire}</textarea></td>
			</tr>
			<tr class="InputFrameLine">
				<td width="10%" height="90" class="table_label" id="fittingRequire_TEXT">配件要求</td>
				<td colspan="3">&nbsp;<textarea name="fittingRequire" cols="60" rows="5" style="width: 90%" wrap="hard">${stock.fittingRequire}</textarea></td>
			</tr>
			<tr class="InputFrameLine">
				<td width="10%" height="90" class="table_label" id="memo_TEXT">备注信息</td>
			  <td colspan="3">&nbsp;<textarea name="memo" cols="60" rows="5" style="width: 90%" wrap="hard">${stock.memo}</textarea></td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</form>
</CENTER>
<%
			out.print(PermissionManager.getInstance().checkSubPermission(
			"5002", request));
%>
${message}
</body>
</html>
	